$(document).ready(function () {

//    获取到数据库中课程目标和评价方式
//    在页面的input中显示


})

function addCourseTarget() {

    var elements = document.getElementsByClassName('courseTarget');
    var td = elements[elements.length - 1].getElementsByTagName("td");
    var targetDetail = td[1].getElementsByTagName("input")[0].value;
    var graRequirement = td[2].getElementsByTagName("input")[0].value;
    var targetWeight = td[3].getElementsByTagName("input")[0].value / 100;

    // if (targetDetail != "" && graRequirement != "" && targetWeight != "") {
    var list = $("#courseTargetList");
    var str = "";
    str += ("<tr class=\"courseTarget\" \"data-index\"=") + (elements.length + 1) + (">");
    str += ("<td><label style=\"font-size: 16px\">课程目标") + (elements.length + 1) + ("</label></td>");
    str += ("<td><input type=\"text\" name=\"courseTargetDetail\" class=\"form-control\"></td>");
    str += ("<td><input type=\"text\" name=\"graduationRequirement\" class=\"form-control\"></td>");
    str += ("<td><input type=\"text\" name=\"targetWeight\" class=\"form-control\"></td>");
    str += ("<td style=\"font-size: 22px\">%</td>");
    str += ("</tr>");

    list.append(str);
    // } else {
    //     alert("请输入课程目标！")
    // }

}

function addCheckType() {
    var elements = document.getElementsByClassName('checkType');
    var td = elements[elements.length - 1].getElementsByTagName("td");
    var checkTypeDetail = td[1].getElementsByTagName("input")[0].value;
    var typeWeight = td[3].getElementsByTagName("input")[0].value / 100;

    // if (checkTypeDetail != "" && typeWeight != "") {
    var list = $("#checkTypeList");
    var str = "";
    str += ("<tr class=\"checkType\">");
    str += ("<td class=\"col-md-3 col-lg-3\" style=\"font-size: 16px\"><label>评价方式") + (elements.length + 1) + ("</label></td>");
    str += ("<td class=\"col-md-4 col-lg-4\"><input type=\"text\" class=\"form-control\" name=\"checkTypeDetail\"></td>");
    str += ("<td class=\"col-md-2 col-lg-2\" style=\"font-size: 16px\"><label>比重</label></td>");
    str += ("<td class=\"col-md-2 col-lg-2\"><input type=\"text\" class=\"form-control\" name=\"typeWeight\"></td>");
    str += ("<td style=\"font-size: 22px\">%</td>");
    str += ("</tr>");

    list.append(str);
    // } else {
    //     alert("请输入评价方式！")
    // }

}

function showCourseTarget(courseTargets) {

    $("[class*='courseTarget']").remove();
    var list = $("#courseTargetList");
    var str = "";

    for (var i = 0; i < courseTargets.length; i++) {

        str += ("<tr class=\"courseTarget\">");
        str += ("<td><label style=\"font-size: 16px\">课程目标") + (i + 1) + ("</label></td>");
        str += ("<td><input type=\"text\" name=\"courseTargetDetail\" class=\"form-control\" value=\"") + courseTargets[i].description + ("\"></td>");
        str += ("<td><input type=\"text\" name=\"graduationRequirement\" class=\"form-control\" value=\"") + courseTargets[i].graduationRequirementNumber + ("\"></td>");
        str += ("<td><input type=\"text\" name=\"targetWeight\" class=\"form-control\" value=\"") + courseTargets[i].weight * 100 + ("\"></td>");
        str += ("<td style=\"font-size: 22px\">%</td>");
        str += ("</tr>");

    }
    list.append(str);
}

function showCheckTypes(checkTypes) {
    $("[class*='checkType']").remove();
    var list = $("#checkTypeList");
    var str = "";

    for (var i = 0; i < checkTypes.length; i++) {

        str += ("<tr class=\"checkType\">");
        str += ("<td class=\"col-md-3 col-lg-3\" style=\"font-size: 16px\"><label>评价方式") + (i + 1) + ("</label></td>");
        str += ("<td class=\"col-md-4 col-lg-4\"><input type=\"text\" class=\"form-control\" name=\"checkTypeDetail\" value=\"")
            + checkTypes[i].evaluationType + ("\"></td>");
        str += ("<td class=\"col-md-2 col-lg-2\" style=\"font-size: 16px\"><label>比重</label></td>");
        str += ("<td class=\"col-md-2 col-lg-2\"><input type=\"text\" class=\"form-control\" name=\"typeWeight\" value=\"")
            + checkTypes[i].weight * 100 + ("\"></td>");
        str += ("<td style=\"font-size: 22px\">%</td>");
        str += ("</tr>");

    }
    list.append(str);
}
